﻿namespace PMS.Client.FrmAdmin
{
    using PMS.BLL;
    using PMS.Client.Controls;
    using PMS.Client.Properties;
    using System;
    using System.ComponentModel;
    using System.Drawing;
    using System.Runtime.CompilerServices;
    using System.Windows.Forms;

    public class FrmList : Form
    {
        private AdminBLL adminBLL = new AdminBLL();
        private DataGridViewTextBoxColumn AdminID;
        private ToolStripButton btnAdd;
        private ToolStripButton btnSetAdminOrgan;
        private ToolStripButton btnUpdate;
        private IContainer components = null;
        private UCDataGridView dataGridView1;
        private DataGridViewTextBoxColumn LoginName;
        private DataGridViewTextBoxColumn OutUseDate;
        private DataGridViewTextBoxColumn RoleName;
        private ToolStrip toolStrip1;

        public FrmList()
        {
            this.InitializeComponent();
        }

        private void btnAdd_Click(object sender, EventArgs e)
        {
            FrmAdd add = new FrmAdd();
            add.ShowDialog();
            if (add.DialogResult == DialogResult.OK)
            {
                this.dataGridView1.DataSource = this.adminBLL.GetList();
            }
        }

        private void btnSetAdminOrgan_Click(object sender, EventArgs e)
        {
            new FrmSetOrgan(this.SelectedAdminID).ShowDialog();
        }

        private void btnUpdate_Click(object sender, EventArgs e)
        {
            FrmUpdate update = new FrmUpdate(this.SelectedAdminID);
            update.ShowDialog();
            if (update.DialogResult == DialogResult.OK)
            {
                this.dataGridView1.DataSource = this.adminBLL.GetList();
            }
        }

        private void dataGridView1_SelectionChanged(object sender, EventArgs e)
        {
            this.SelectedAdminID = 0;
            if ((this.dataGridView1.SelectedRows.Count > 0) && (this.dataGridView1.SelectedRows[0].Cells["AdminID"].Value != null))
            {
                this.SelectedAdminID = int.Parse(this.dataGridView1.SelectedRows[0].Cells["AdminID"].Value.ToString());
            }
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void FrmList_FormClosing(object sender, FormClosingEventArgs e)
        {
            base.DialogResult = DialogResult.OK;
        }

        private void FrmList_Load(object sender, EventArgs e)
        {
            this.dataGridView1.AutoGenerateColumns = false;
            this.dataGridView1.DataSource = this.adminBLL.GetList();
        }

        private void InitializeComponent()
        {
            this.components = new Container();
            DataGridViewCellStyle style = new DataGridViewCellStyle();
            DataGridViewCellStyle style2 = new DataGridViewCellStyle();
            ComponentResourceManager manager = new ComponentResourceManager(typeof(FrmList));
            this.dataGridView1 = new UCDataGridView(this.components);
            this.AdminID = new DataGridViewTextBoxColumn();
            this.LoginName = new DataGridViewTextBoxColumn();
            this.RoleName = new DataGridViewTextBoxColumn();
            this.OutUseDate = new DataGridViewTextBoxColumn();
            this.toolStrip1 = new ToolStrip();
            this.btnAdd = new ToolStripButton();
            this.btnUpdate = new ToolStripButton();
            this.btnSetAdminOrgan = new ToolStripButton();
            ((ISupportInitialize) this.dataGridView1).BeginInit();
            this.toolStrip1.SuspendLayout();
            base.SuspendLayout();
            this.dataGridView1.AllowUserToAddRows = false;
            this.dataGridView1.AllowUserToDeleteRows = false;
            this.dataGridView1.AllowUserToResizeRows = false;
            this.dataGridView1.BackgroundColor = Color.FromArgb(0xa4, 0xc4, 0xeb);
            this.dataGridView1.BorderStyle = BorderStyle.None;
            this.dataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
            this.dataGridView1.Columns.AddRange(new DataGridViewColumn[] { this.AdminID, this.LoginName, this.RoleName, this.OutUseDate });
            style.Alignment = DataGridViewContentAlignment.MiddleLeft;
            style.BackColor = Color.FromArgb(0xd9, 0xea, 0xf7);
            style.Font = new Font("宋体", 9f, FontStyle.Regular, GraphicsUnit.Point, 0x86);
            style.ForeColor = SystemColors.ControlText;
            style.SelectionBackColor = SystemColors.Highlight;
            style.SelectionForeColor = SystemColors.ControlText;
            style.WrapMode = DataGridViewTriState.False;
            this.dataGridView1.DefaultCellStyle = style;
            this.dataGridView1.Dock = DockStyle.Fill;
            this.dataGridView1.EnableHeadersVisualStyles = false;
            this.dataGridView1.GridColor = Color.FromArgb(0xd0, 0xd7, 0xe5);
            this.dataGridView1.HighlightSelectedColumnHeaders = false;
            this.dataGridView1.Location = new Point(0, 0x38);
            this.dataGridView1.MultiSelect = false;
            this.dataGridView1.Name = "dataGridView1";
            this.dataGridView1.ReadOnly = true;
            this.dataGridView1.RowTemplate.Height = 0x17;
            this.dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
            this.dataGridView1.Size = new Size(0x27e, 0x175);
            this.dataGridView1.TabIndex = 11;
            this.dataGridView1.SelectionChanged += new EventHandler(this.dataGridView1_SelectionChanged);
            this.AdminID.DataPropertyName = "AdminID";
            style2.Alignment = DataGridViewContentAlignment.MiddleCenter;
            style2.BackColor = Color.FromArgb(0xd9, 0xea, 0xf7);
            this.AdminID.DefaultCellStyle = style2;
            this.AdminID.HeaderText = "ID";
            this.AdminID.Name = "AdminID";
            this.AdminID.ReadOnly = true;
            this.AdminID.Visible = false;
            this.AdminID.Width = 50;
            this.LoginName.DataPropertyName = "LoginName";
            this.LoginName.HeaderText = "用户名";
            this.LoginName.Name = "LoginName";
            this.LoginName.ReadOnly = true;
            this.LoginName.Width = 130;
            this.RoleName.DataPropertyName = "RoleName";
            this.RoleName.HeaderText = "角色";
            this.RoleName.Name = "RoleName";
            this.RoleName.ReadOnly = true;
            this.RoleName.Width = 150;
            this.OutUseDate.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
            this.OutUseDate.DataPropertyName = "OutUseDate";
            this.OutUseDate.HeaderText = "过期时间";
            this.OutUseDate.Name = "OutUseDate";
            this.OutUseDate.ReadOnly = true;
            this.toolStrip1.Items.AddRange(new ToolStripItem[] { this.btnAdd, this.btnUpdate, this.btnSetAdminOrgan });
            this.toolStrip1.Location = new Point(0, 0);
            this.toolStrip1.Name = "toolStrip1";
            this.toolStrip1.RenderMode = ToolStripRenderMode.System;
            this.toolStrip1.Size = new Size(0x27e, 0x38);
            this.toolStrip1.TabIndex = 12;
            this.toolStrip1.Text = "toolStrip1";
            this.btnAdd.Image = Resources.Icons_add;
            this.btnAdd.ImageScaling = ToolStripItemImageScaling.None;
            this.btnAdd.ImageTransparentColor = Color.Magenta;
            this.btnAdd.Name = "btnAdd";
            this.btnAdd.Size = new Size(60, 0x35);
            this.btnAdd.Text = "添加用户";
            this.btnAdd.TextImageRelation = TextImageRelation.ImageAboveText;
            this.btnAdd.Click += new EventHandler(this.btnAdd_Click);
            this.btnUpdate.Image = Resources.Icons_update;
            this.btnUpdate.ImageScaling = ToolStripItemImageScaling.None;
            this.btnUpdate.ImageTransparentColor = Color.Magenta;
            this.btnUpdate.Name = "btnUpdate";
            this.btnUpdate.Size = new Size(60, 0x35);
            this.btnUpdate.Text = "修改用户";
            this.btnUpdate.TextImageRelation = TextImageRelation.ImageAboveText;
            this.btnUpdate.Click += new EventHandler(this.btnUpdate_Click);
            this.btnSetAdminOrgan.Image = Resources.settitle;
            this.btnSetAdminOrgan.ImageScaling = ToolStripItemImageScaling.None;
            this.btnSetAdminOrgan.ImageTransparentColor = Color.Magenta;
            this.btnSetAdminOrgan.Name = "btnSetAdminOrgan";
            this.btnSetAdminOrgan.Size = new Size(0x54, 0x35);
            this.btnSetAdminOrgan.Text = "设置机构权限";
            this.btnSetAdminOrgan.TextImageRelation = TextImageRelation.ImageAboveText;
            this.btnSetAdminOrgan.Click += new EventHandler(this.btnSetAdminOrgan_Click);
            base.AutoScaleDimensions = new SizeF(6f, 12f);
            base.AutoScaleMode = AutoScaleMode.Font;
            base.ClientSize = new Size(0x27e, 0x1ad);
            base.Controls.Add(this.dataGridView1);
            base.Controls.Add(this.toolStrip1);
            base.Icon = (Icon) manager.GetObject("$this.Icon");
            base.Name = "FrmList";
            base.StartPosition = FormStartPosition.CenterScreen;
            this.Text = "用户列表";
            base.FormClosing += new FormClosingEventHandler(this.FrmList_FormClosing);
            base.Load += new EventHandler(this.FrmList_Load);
            ((ISupportInitialize) this.dataGridView1).EndInit();
            this.toolStrip1.ResumeLayout(false);
            this.toolStrip1.PerformLayout();
            base.ResumeLayout(false);
            base.PerformLayout();
        }

        public int SelectedAdminID { get; set; }
    }
}

